<?php
$page=$_GET['page']??1;
$pagesize=3;
$limit=($page-1)*$pagesize;
$dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
$sql= 'select * from xw';
$arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);//取得所有行
$rowsNumber = count($arr);
$pagecount=ceil($rowsNumber/$pagesize);
//echo $rowsNumber;
$sel=$_GET['news_title']??'';
if($sel!='')
{
    $memcache_obj=memcache_connect('127.0.0.1',11211);//连接池
    $arr=$memcache_obj->get($sel);//获取数据
    if($arr=='')
    {
        echo "没有缓存";
        $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
        $sql="select * from xw where news_title like '%$sel%' limit $limit,$pagesize";
        $arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
        $memcache_obj->set($sel,$arr);
    }
}
else
{
    $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
    $sql="select * from xw where news_title like '%$sel%' limit $limit,$pagesize";
    $arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);

}
?>
<form method="get">
    <input type="text" name="news_title">
    <input type="submit" value="搜索">
</form>
<a href="jthall.php?page=<?php echo $page?>">批量静态化</a>
<table border="1">
    <tr>
        <td>新闻分类</td>
        <td>新闻分类url</td>
        <td>新闻标题</td>
        <td>新闻标题url</td>
        <td>操作</td>
    </tr>
    <?php foreach($arr as $k=>$value) { ?>
        <tr>
            <td><?php echo $value['news_type']?></td>
            <td><?php echo $value['news_type_url']?></td>
            <td><?php echo $value['news_title']?></td>
            <td><a href="jth.php?id=<?php echo $value['id']?>">静态化</a></td>

        </tr>
    <?php } ?>
</table>
<a href="zhanshi.php?page=1">首页</a>
<a href="zhanshi.php?page=<?php echo $page-1?>&news_title=<?php echo $sel?>">上一页</a>
<a href="zhanshi.php?page=<?php echo $page+1?>&news_title=<?php echo $sel?>">下一页</a>
<a href="zhanshi.php?page=<?php echo $pagecount?>&news_title=<?php echo $sel?>">尾页</a>
